package com.uwlaser.rest;

import com.uwlaser.annotation.Log;
import com.uwlaser.domain.DataProductPathLog;
import com.uwlaser.service.DataProductPathLogService;
import com.uwlaser.service.dto.DataProductPathLogDto;
import com.uwlaser.service.dto.DataProductPathLogQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Set;

/**
* @author zk-Qin
* @date 2022-05-11
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "工艺路线操作日志管理")
@RequestMapping("/api/dataProductPathLog")
public class DataProductPathLogController {

    private final DataProductPathLogService dataProductPathLogService;

    @GetMapping
    @Log("查询工艺路线操作日志")
    @ApiOperation("查询工艺路线操作日志")
    @PreAuthorize("@el.check('dataProductPathLog:list','dataMain:list')")
    public ResponseEntity query(DataProductPathLogQueryParam query, Pageable pageable){
        return new ResponseEntity<>(dataProductPathLogService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增工艺路线操作日志")
    @ApiOperation("新增工艺路线操作日志")
    @PreAuthorize("@el.check('dataProductPathLog:add')")
    public ResponseEntity create(@Validated @RequestBody DataProductPathLogDto resources){
        return new ResponseEntity<>(dataProductPathLogService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改工艺路线操作日志")
    @ApiOperation("修改工艺路线操作日志")
    @PreAuthorize("@el.check('dataProductPathLog:edit')")
    public ResponseEntity update(@Validated @RequestBody DataProductPathLogDto resources){
        dataProductPathLogService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除工艺路线操作日志")
    @ApiOperation("删除工艺路线操作日志")
    @PreAuthorize("@el.check('dataProductPathLog:del')")
    public ResponseEntity delete(@RequestBody Set<Integer> ids) {
        dataProductPathLogService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出工艺路线操作日志")
    @ApiOperation("导出工艺路线操作日志")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('dataProductPathLog:list')")
    public void download(HttpServletResponse response, DataProductPathLogQueryParam query) throws IOException {
        dataProductPathLogService.download(dataProductPathLogService.queryAll(query), response);
    }*/

}
